/*
 *         (C) COPYRIGHT Ingenic Limited
 *              ALL RIGHT RESERVED
 *
 * File        : uranus_common_type.h
 * Authors     : lzwang
 * Create Time : 2021-10-14 18:14:03 (CST)
 * Description :
 *
 */

#ifndef __MAGIK_URANUS_COMMON_COMMON_UTILS_H__
#define __MAGIK_URANUS_COMMON_COMMON_UTILS_H__

#include "uranus_common_type.h"
#include <stddef.h>
#include <stdint.h>
#include <vector>

template <typename T>
int uranus_cmp_array(T *a, T *b, int len) {
    if ((a == nullptr) && (b == nullptr))
        return 0;
    if ((a != nullptr) && (b != nullptr)) {
        for (int ii = 0; ii < len; ii++) {
            if (a[ii] != b[ii])
                return -1;
        }
        return 0;
    } else
        return -1;
}

namespace magik {
namespace uranus {

enum class BsPadType : int URANUS_API {
    NONE = -1,        /*no pad value*/
    BOTTOM_RIGHT = 0, /*fill pad value in bottom and right of output image*/
    SYMMETRY = 1,     /*fill pad value around the output image symmetrically*/
};

struct URANUS_API BsBaseParam {
    ChannelLayout in_layout;  /*input format:NV12 BGRA RGBA*/
    ChannelLayout out_layout; /*output format:NV12 BGRA RGBA*/
    /*coef_off_enable: enable or disable coef and offset in color format convert
     *true: calculate by coef and offset
     *false: calculate by default parameters*/
    bool coef_off_enable = false;
    /*true:resize->resize,convert
     *false: convert,resize->resize*/
    bool first_resize = false;
    uint32_t coef[9];   /*nv12 to bgra param*/
    uint32_t offset[2]; /*nv12 to bgra pixel offset*/
};

struct URANUS_API AddressDesc {
    void *phy_addr = NULL; /*physical address*/
    void *vir_addr = NULL; /*virtual address*/
};
struct URANUS_API BsCommonParam : public BsBaseParam {
    BsPadType pad_type; /*BOTTOM_RIGHT or SYMMETRY*/
    uint8_t pad_val;    /*value of pad*/
    float scale_x = 0.0;
    float scale_y = 0.0;
    int real_chn = 0;
    int input_height;      /*input image height*/
    int input_width;       /*input image width*/
    int input_line_stride; /*input line stride*/
    AddressDesc addr_attr;
};

struct URANUS_API GetZoneParam {
    std::vector<int32_t> input_shape;  /*HWC*/
    std::vector<int32_t> output_shape; /*HWC*/
    float threshold;
};

typedef struct URANUS_API Bbox_t {
    float x0;
    float y0;
    float x1;
    float y1;
} Box_t;

typedef struct URANUS_API ObjBbox_t {
    Bbox_t box;
    float score;
    int class_id;
} ObjectBbox_t;

enum class NmsType : int URANUS_API { HARD_NMS = 0, SOFT_NMS = 1 };
enum class DetectorType : int URANUS_API { YOLOV3 = 0, YOLOV5 = 1, YOLOV8 = 2 };

typedef NmsType NmsType_t;
typedef DetectorType DetectorType_t;
} // namespace uranus
} // namespace magik
#endif /* __MAGIK_URANUS_COMMON_COMMON_UTILS_H__ */
